package store

import (
	"go_gvm_mini/instructions/base"
	"go_gvm_mini/rtda"
)

type DSTORE struct {
	base.Index8Instruction
}

func (self *DSTORE) Execute(jFrame *rtda.JFrame) {
	_dstore(jFrame, self.Index)
}

type DSTORE_0 struct {
	base.NoOperandsInstruction
}

func (self *DSTORE_0) Execute(jFrame *rtda.JFrame) {
	_dstore(jFrame, 0)
}

type DSTORE_1 struct {
	base.NoOperandsInstruction
}

func (self *DSTORE_1) Execute(jFrame *rtda.JFrame) {
	_dstore(jFrame, 1)
}

type DSTORE_2 struct {
	base.NoOperandsInstruction
}

func (self *DSTORE_2) Execute(jFrame *rtda.JFrame) {
	_dstore(jFrame, 2)
}

type DSTORE_3 struct {
	base.NoOperandsInstruction
}

func (self *DSTORE_3) Execute(jFrame *rtda.JFrame) {
	_dstore(jFrame, 3)
}

func _dstore(frame *rtda.JFrame, index uint) {
	val := frame.OperandStack().PopDouble()
	frame.LocalVars().SetDouble(index, val)
}
